package com.tarena.lbs.stock.web.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.pojo.stock.param.CouponStockParam;
import com.tarena.lbs.pojo.stock.vo.CouponStockVO;
import com.tarena.lbs.stock.web.converter.CouponStockConverter;
import com.tarena.lbs.stock.web.service.CouponStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/admin/stock")
@Api(tags = "库存管理")
public class CouponStockController {

    @Resource
    private CouponStockService couponStockService;

    @Resource
    private CouponStockConverter couponStockConverter;

    @PostMapping("/insert")
    @ApiOperation("新增库存")
    public Result<Void> insert(@Validated @RequestBody CouponStockParam param) {
        couponStockService.insert(param);
        return Result.success();
    }

    @PostMapping("/update")
    @ApiOperation("更新库存")
    public Result<Void> update(@Validated @RequestBody CouponStockParam param) {
        couponStockService.update(param);
        return Result.success();
    }

    @GetMapping("/detail")
    @ApiOperation("查询库存")
    public Result<CouponStockVO> detail(Integer couponId) {
        return new Result(couponStockConverter.bo2vo(couponStockService.getDetail(couponId)));
    }

}
